package com.chaoyong.higo.adapter;

import java.util.ArrayList;
import java.util.List;

import com.chaoyong.higo.R;
import com.chaoyong.higo.bean.DemoBean;
import com.chaoyong.higo.utils.Values;
import com.lidroid.xutils.BitmapUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SettlementAdapter extends BaseAdapter {

	private Activity context;
	private List<DemoBean.DataEntity> data;
	private LayoutInflater inflater;
	private BitmapUtils utils;
	
	public SettlementAdapter(Activity context) {
		this.context = context;
		inflater = LayoutInflater.from(context);
		utils = new BitmapUtils(context);
	}
	
	public void changeDatas(List<DemoBean.DataEntity> data) {
		this.data = data;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return data == null ? 0 : data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_pay_lv, null);
			holder.iv = (ImageView) convertView.findViewById(R.id.item_pay_lv_iamge);
			holder.title = (TextView) convertView.findViewById(R.id.item_pay_lv_title);
			holder.nam = (TextView) convertView.findViewById(R.id.item_pay_lv_nam);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		//BitmapUtils utils = new BitmapUtils(context);
		//utils.display(holder.iv, Values.BASE_IMAGE_URL + data.get(position).getCover_img());
		String img = data.get(position).getCover_img();
		if(img.contains("|")){
			//ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + data.get(position).getCover_img().split("|")[0], holder.iv);
			String image = img.split("\\|")[0];
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + image, holder.iv);
		}else{
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + data.get(position).getCover_img(), holder.iv);
		}
		
		holder.title.setText(data.get(position).getGoods_name());
		holder.nam.setText(data.get(position).getNum() + "人次/" + "￥" + data.get(position).getNum());
		return convertView;
	}

	class ViewHolder{
		ImageView iv;
		TextView title,nam;
	}
	
}
